package com.cainiao.recycleviewtest

import android.os.Bundle
import androidx.activity.enableEdgeToEdge
import androidx.appcompat.app.AppCompatActivity
import androidx.recyclerview.widget.LinearLayoutManager
import androidx.recyclerview.widget.RecyclerView

class MainActivity : AppCompatActivity() {

    private val fruitList = ArrayList<Fruit>()

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        enableEdgeToEdge()
        setContentView(R.layout.activity_main)
        initFruits()
        val layoutManager = LinearLayoutManager(this)
        var recyclerView:RecyclerView = findViewById(R.id.recyclerView)
        recyclerView.layoutManager = layoutManager
        recyclerView.adapter = FruitAdapter(fruitList)
    }
    private fun initFruits(){
        repeat(2){
            fruitList.add(Fruit("Apple",R.mipmap.apple_pic))
            fruitList.add(Fruit("Banana",R.mipmap.apple_pic))
            fruitList.add(Fruit("Orange",R.mipmap.apple_pic))
            fruitList.add(Fruit("Watermelon",R.mipmap.apple_pic))
            fruitList.add(Fruit("Pear",R.mipmap.apple_pic))
            fruitList.add(Fruit("Grape",R.mipmap.apple_pic))
            fruitList.add(Fruit("Pineapple",R.mipmap.apple_pic))
            fruitList.add(Fruit("Strawberry",R.mipmap.apple_pic))
            fruitList.add(Fruit("Cherry",R.mipmap.apple_pic))
            fruitList.add(Fruit("Mango",R.mipmap.apple_pic))
        }
    }
}